﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Win.CSkin.Test
{
    public partial class frmModelCreate : Form
    {
        public frmModelCreate()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 生成实体类（字段间以,分隔）
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtFields.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入字段");
                return;
            }

            //去除空格 eg:name1, name2 ,name3。。。
            string fields = Regex.Replace(txtFields.Text, @"\s", ""); //txtFields.Text.Trim().Replace(" ","");

            var fieldArr = fields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            StringBuilder model = new StringBuilder(@"
                /// <summary>
                /// 
                /// </summary>
                public class Demo
                {");

            foreach (var field in fieldArr)
            {
                model.Append($@"
                    /// <summary>
                    /// 
                    /// </summary>
                    public string {field}");
                model.Append(" { get; set; }");
            }

            model.Append(" \n         }");

            txtModel.Text = model.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (txtModel.Text.Trim().Length > 0)
            {
                Clipboard.SetDataObject(txtModel.Text.Trim());
            }
        }
    }
}
